package com.yunhai.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.tms.TmsStoreGroupEntity;
import com.yunhai.model.vo.sys.SysVersionManageVo;
import com.yunhai.model.vo.tms.TmsStoreGroupQuery;
import com.yunhai.model.vo.tms.TmsStoreGroupVo;
import com.yunhai.store.service.TmsStoreGroupService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/storeGroup")
public class TmsStoreGroupController {

    @Resource
    private TmsStoreGroupService tmsStoreGroupService;


    /**
     * 获取 TmsStoreGroup 分页列表
     */
    @GetMapping("/pagination")
    public Ret getTmsStoreGroupPagination(PaginationVo paginationVo, TmsStoreGroupQuery tmsStoreGroupQuery ) throws Exception {
        IPage page = tmsStoreGroupService.getTmsStoreGroupPagination(paginationVo, tmsStoreGroupQuery );
        return Ret.toPage(page);
    }


    /**
     * 获取 TmsStoreGroup 所有数据
     */
    @GetMapping("/allList")
    public Ret getTmsStoreGroupAllList( TmsStoreGroupQuery tmsStoreGroupQuery ) throws Exception {
        List<TmsStoreGroupEntity> list = tmsStoreGroupService.getTmsStoreGroupAllList( tmsStoreGroupQuery );
        return Ret.ok(list);
    }

    /**
     * 获取 TmsStoreGroup 详情
    */
   @GetMapping("/{id}")
   public Ret getTmsStoreGroupDetail(@PathVariable Long id) throws Exception {

       TmsStoreGroupEntity tmsStoreGroup = tmsStoreGroupService.getTmsStoreGroupDetail(id);
       return Ret.ok(tmsStoreGroup);
   }


    /**
     * 新增 TmsStoreGroup
     * */
    @PostMapping("")
    public Ret addTmsStoreGroup(@RequestBody TmsStoreGroupVo tmsStoreGroupVo) throws Exception {
        if( tmsStoreGroupVo.getParentId() == null ){
            tmsStoreGroupVo.setParentId(0L);
            tmsStoreGroupVo.setLevel(1);
        }
        tmsStoreGroupService.addTmsStoreGroup(tmsStoreGroupVo);
        return Ret.ok();
    }


    @PostMapping("/batchLoad")
    public Ret batchAddTmsStoreGroupByExcelFile(@RequestParam("file") MultipartFile file ) throws Exception {

        tmsStoreGroupService.batchAddTmsStoreGroupByExcelFile( file );
        return Ret.ok();
    }


    /**
     * 更新 TmsStoreGroup
     * */
    @PutMapping("")
    public Ret updateTmsStoreGroup(@RequestBody TmsStoreGroupVo tmsStoreGroupVo) throws Exception {

        tmsStoreGroupService.updateTmsStoreGroup(tmsStoreGroupVo);
        return Ret.ok();
    }


    /**
     * 删除 TmsStoreGroup
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveTmsStoreGroup( @RequestBody List<Long> ids ) throws Exception {

        tmsStoreGroupService.batchRemoveTmsStoreGroup(ids);
        return Ret.ok();
    }
}

  